package com.seal.commons.quartz.xxljob;

import com.seal.commons.quartz.QuartzJobHandler;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 功能描述: <br/>
 *
 * @author yong.huang
 * @date: 2020-10-30 10:24<br/>
 * @since JDK 1.8
 */
public class XxlJobQuartzJobHandlerAdapter extends IJobHandler{

    public static final Logger LOGGER = LoggerFactory.getLogger(XxlJobQuartzJobHandlerAdapter.class);

    private String name;

    private QuartzJobHandler quartzJobHandler;

    public  XxlJobQuartzJobHandlerAdapter(String name, QuartzJobHandler quartzJobHandler){
        this.quartzJobHandler = quartzJobHandler;
        this.name = name;
    }

    @Override
    public ReturnT<String> execute(String s) {
        try {
            quartzJobHandler.execute(s);
            LOGGER.info("jobName:[{}] execute success", name);
            return IJobHandler.SUCCESS;
        }catch (Exception e){
            LOGGER.info("jobName:[{}] execute error", name, e);
            return IJobHandler.FAIL;
        }
    }

}